<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perliol - C API for Perl&#39;s implementation of IO in Layers. - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perliol">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perliol.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perliol">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perliol">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perliol">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perliol">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perliol">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perliol">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perliol">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perliol">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perliol">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perliol">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perliol">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perliol">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perliol">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perliol">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perliol">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perliol">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perliol">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perliol">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perliol">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perliol">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perliol">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perliol">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perliol">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perliol">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perliol">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perliol">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perliol">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perliol">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perliol">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perliol">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perliol">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perliol">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perliol">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perliol">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perliol">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perliol">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perliol">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perliol">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perliol">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perliol">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perliol">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perliol">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perliol">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perliol">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perliol">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perliol">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perliol">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perliol">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perliol">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perliol">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perliol">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perliol">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perliol">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perliol">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perliol">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perliol">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perliol">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perliol">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perliol">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perliol">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perliol">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perliol">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perliol">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perliol">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perliol">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perliol">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perliol">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perliol">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perliol">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perliol">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perliol">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perliol">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perliol">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perliol">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perliol">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perliol">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perliol">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perliol">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perliol">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perliol">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perliol.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perliol">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perliol">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perliol">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perliol">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perliol">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perliol">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perliol">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perliol">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perliol">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perliol">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perliol">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perliol">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perliol">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perliol">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perliol">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perliol">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perliol">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perliol">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perliol">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perliol">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perliol">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perliol">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perliol">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perliol">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perliol">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perliol">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perliol">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perliol">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perliol">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perliol">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perliol">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perliol">5.35.1</a>
          <a class="dropdown-item active" href="perliol.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perliol.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perliol.html">perliol</a>
          <div id="more">
            (<a href="perliol.txt">source</a>,
            <a href="https://metacpan.org/pod/perliol">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perliol.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#DESCRIPTION">DESCRIPTION</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perliol.html#History-and-Background">History and Background</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Basic-Structure">Basic Structure</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Layers-vs-Disciplines">Layers vs Disciplines</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Data-Structures">Data Structures</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Functions-and-Attributes">Functions and Attributes</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Per-instance-Data">Per-instance Data</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Layers-in-action.">Layers in action.</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Per-instance-flag-bits">Per-instance flag bits</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Methods-in-Detail">Methods in Detail</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Utilities">Utilities</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Implementing-PerlIO-Layers">Implementing PerlIO Layers</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Core-Layers">Core Layers</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#Extension-Layers">Extension Layers</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perliol.html#TODO">TODO</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perliol.html#NAME">#</a>NAME</h1>

<p>perliol - C API for Perl&#39;s implementation of IO in Layers.</p>

<h1 id="SYNOPSIS"><a class="permalink" href="perliol.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code class="plaintext">/* Defining a layer ... */
#include &lt;perliol.h&gt;</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="perliol.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>This document describes the behavior and implementation of the PerlIO abstraction described in <a href="perlapio.html">perlapio</a> when <code>USE_PERLIO</code> is defined.</p>

<h2 id="History-and-Background"><a class="permalink" href="perliol.html#History-and-Background">#</a><a id="History"></a>History and Background</h2>

<p>The PerlIO abstraction was introduced in perl5.003_02 but languished as just an abstraction until perl5.7.0. However during that time a number of perl extensions switched to using it, so the API is mostly fixed to maintain (source) compatibility.</p>

<p>The aim of the implementation is to provide the PerlIO API in a flexible and platform neutral manner. It is also a trial of an &quot;Object Oriented C, with vtables&quot; approach which may be applied to Raku.</p>

<h2 id="Basic-Structure"><a class="permalink" href="perliol.html#Basic-Structure">#</a><a id="Basic"></a>Basic Structure</h2>

<p>PerlIO is a stack of layers.</p>

<p>The low levels of the stack work with the low-level operating system calls (file descriptors in C) getting bytes in and out, the higher layers of the stack buffer, filter, and otherwise manipulate the I/O, and return characters (or bytes) to Perl. Terms <i>above</i> and <i>below</i> are used to refer to the relative positioning of the stack layers.</p>

<p>A layer contains a &quot;vtable&quot;, the table of I/O operations (at C level a table of function pointers), and status flags. The functions in the vtable implement operations like &quot;open&quot;, &quot;read&quot;, and &quot;write&quot;.</p>

<p>When I/O, for example &quot;read&quot;, is requested, the request goes from Perl first down the stack using &quot;read&quot; functions of each layer, then at the bottom the input is requested from the operating system services, then the result is returned up the stack, finally being interpreted as Perl data.</p>

<p>The requests do not necessarily go always all the way down to the operating system: that&#39;s where PerlIO buffering comes into play.</p>

<p>When you do an open() and specify extra PerlIO layers to be deployed, the layers you specify are &quot;pushed&quot; on top of the already existing default stack. One way to see it is that &quot;operating system is on the left&quot; and &quot;Perl is on the right&quot;.</p>

<p>What exact layers are in this default stack depends on a lot of things: your operating system, Perl version, Perl compile time configuration, and Perl runtime configuration. See <a href="PerlIO.html">PerlIO</a>, <a href="perlrun.html#PERLIO">&quot;PERLIO&quot; in perlrun</a>, and <a href="open.html">open</a> for more information.</p>

<p>binmode() operates similarly to open(): by default the specified layers are pushed on top of the existing stack.</p>

<p>However, note that even as the specified layers are &quot;pushed on top&quot; for open() and binmode(), this doesn&#39;t mean that the effects are limited to the &quot;top&quot;: PerlIO layers can be very &#39;active&#39; and inspect and affect layers also deeper in the stack. As an example there is a layer called &quot;raw&quot; which repeatedly &quot;pops&quot; layers until it reaches the first layer that has declared itself capable of handling binary data. The &quot;pushed&quot; layers are processed in left-to-right order.</p>

<p>sysopen() operates (unsurprisingly) at a lower level in the stack than open(). For example in Unix or Unix-like systems sysopen() operates directly at the level of file descriptors: in the terms of PerlIO layers, it uses only the &quot;unix&quot; layer, which is a rather thin wrapper on top of the Unix file descriptors.</p>

<h2 id="Layers-vs-Disciplines"><a class="permalink" href="perliol.html#Layers-vs-Disciplines">#</a><a id="Layers"></a>Layers vs Disciplines</h2>

<p>Initial discussion of the ability to modify IO streams behaviour used the term &quot;discipline&quot; for the entities which were added. This came (I believe) from the use of the term in &quot;sfio&quot;, which in turn borrowed it from &quot;line disciplines&quot; on Unix terminals. However, this document (and the C code) uses the term &quot;layer&quot;.</p>

<p>This is, I hope, a natural term given the implementation, and should avoid connotations that are inherent in earlier uses of &quot;discipline&quot; for things which are rather different.</p>

<h2 id="Data-Structures"><a class="permalink" href="perliol.html#Data-Structures">#</a><a id="Data"></a>Data Structures</h2>

<p>The basic data structure is a PerlIOl:</p>

<pre><code>typedef struct _PerlIO PerlIOl;
typedef struct _PerlIO_funcs PerlIO_funcs;
typedef PerlIOl *PerlIO;

struct _PerlIO
{
 PerlIOl *	next;       /* Lower layer */
 PerlIO_funcs *	tab;        /* Functions for this layer */
 U32		flags;      /* Various flags for state */
};</code></pre>

<p>A <code>PerlIOl *</code> is a pointer to the struct, and the <i>application</i> level <code>PerlIO *</code> is a pointer to a <code>PerlIOl *</code> - i.e. a pointer to a pointer to the struct. This allows the application level <code>PerlIO *</code> to remain constant while the actual <code>PerlIOl *</code> underneath changes. (Compare perl&#39;s <code>SV *</code> which remains constant while its <code>sv_any</code> field changes as the scalar&#39;s type changes.) An IO stream is then in general represented as a pointer to this linked-list of &quot;layers&quot;.</p>

<p>It should be noted that because of the double indirection in a <code>PerlIO *</code>, a <code>&amp;(perlio-&gt;next)</code> &quot;is&quot; a <code>PerlIO *</code>, and so to some degree at least one layer can use the &quot;standard&quot; API on the next layer down.</p>

<p>A &quot;layer&quot; is composed of two parts:</p>

<ol>

<li><p>The functions and attributes of the &quot;layer class&quot;.</p>

</li>
<li><p>The per-instance data for a particular handle.</p>

</li>
</ol>

<h2 id="Functions-and-Attributes"><a class="permalink" href="perliol.html#Functions-and-Attributes">#</a><a id="Functions"></a>Functions and Attributes</h2>

<p>The functions and attributes are accessed via the &quot;tab&quot; (for table) member of <code>PerlIOl</code>. The functions (methods of the layer &quot;class&quot;) are fixed, and are defined by the <code>PerlIO_funcs</code> type. They are broadly the same as the public <code>PerlIO_xxxxx</code> functions:</p>

<pre><code>struct _PerlIO_funcs
{
 Size_t     fsize;
 char *     name;
 Size_t     size;
 IV         kind;
 IV         (*Pushed)(pTHX_ PerlIO *f,
                            const char *mode,
                            SV *arg,
                            PerlIO_funcs *tab);
 IV         (*Popped)(pTHX_ PerlIO *f);
 PerlIO *   (*Open)(pTHX_ PerlIO_funcs *tab,
                          PerlIO_list_t *layers, IV n,
                          const char *mode,
                          int fd, int imode, int perm,
                          PerlIO *old,
                          int narg, SV **args);
 IV         (*Binmode)(pTHX_ PerlIO *f);
 SV *       (*Getarg)(pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags)
 IV         (*Fileno)(pTHX_ PerlIO *f);
 PerlIO *   (*Dup)(pTHX_ PerlIO *f,
                         PerlIO *o,
                         CLONE_PARAMS *param,
                         int flags)
 /* Unix-like functions - cf sfio line disciplines */
 SSize_t    (*Read)(pTHX_ PerlIO *f, void *vbuf, Size_t count);
 SSize_t    (*Unread)(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
 SSize_t    (*Write)(pTHX_ PerlIO *f, const void *vbuf, Size_t count);
 IV         (*Seek)(pTHX_ PerlIO *f, Off_t offset, int whence);
 Off_t      (*Tell)(pTHX_ PerlIO *f);
 IV         (*Close)(pTHX_ PerlIO *f);
 /* Stdio-like buffered IO functions */
 IV         (*Flush)(pTHX_ PerlIO *f);
 IV         (*Fill)(pTHX_ PerlIO *f);
 IV         (*Eof)(pTHX_ PerlIO *f);
 IV         (*Error)(pTHX_ PerlIO *f);
 void       (*Clearerr)(pTHX_ PerlIO *f);
 void       (*Setlinebuf)(pTHX_ PerlIO *f);
 /* Perl&#39;s snooping functions */
 STDCHAR *  (*Get_base)(pTHX_ PerlIO *f);
 Size_t     (*Get_bufsiz)(pTHX_ PerlIO *f);
 STDCHAR *  (*Get_ptr)(pTHX_ PerlIO *f);
 SSize_t    (*Get_cnt)(pTHX_ PerlIO *f);
 void       (*Set_ptrcnt)(pTHX_ PerlIO *f,STDCHAR *ptr,SSize_t cnt);
};</code></pre>

<p>The first few members of the struct give a function table size for compatibility check &quot;name&quot; for the layer, the size to <code>malloc</code> for the per-instance data, and some flags which are attributes of the class as whole (such as whether it is a buffering layer), then follow the functions which fall into four basic groups:</p>

<ol>

<li><p>Opening and setup functions</p>

</li>
<li><p>Basic IO operations</p>

</li>
<li><p>Stdio class buffering options.</p>

</li>
<li><p>Functions to support Perl&#39;s traditional &quot;fast&quot; access to the buffer.</p>

</li>
</ol>

<p>A layer does not have to implement all the functions, but the whole table has to be present. Unimplemented slots can be NULL (which will result in an error when called) or can be filled in with stubs to &quot;inherit&quot; behaviour from a &quot;base class&quot;. This &quot;inheritance&quot; is fixed for all instances of the layer, but as the layer chooses which stubs to populate the table, limited &quot;multiple inheritance&quot; is possible.</p>

<h2 id="Per-instance-Data"><a class="permalink" href="perliol.html#Per-instance-Data">#</a><a id="Per"></a>Per-instance Data</h2>

<p>The per-instance data are held in memory beyond the basic PerlIOl struct, by making a PerlIOl the first member of the layer&#39;s struct thus:</p>

<pre><code>typedef struct
{
 struct _PerlIO base;       /* Base &quot;class&quot; info */
 STDCHAR *	buf;        /* Start of buffer */
 STDCHAR *	end;        /* End of valid part of buffer */
 STDCHAR *	ptr;        /* Current position in buffer */
 Off_t		posn;       /* Offset of buf into the file */
 Size_t		bufsiz;     /* Real size of buffer */
 IV		oneword;    /* Emergency buffer */
} PerlIOBuf;</code></pre>

<p>In this way (as for perl&#39;s scalars) a pointer to a PerlIOBuf can be treated as a pointer to a PerlIOl.</p>

<h2 id="Layers-in-action."><a class="permalink" href="perliol.html#Layers-in-action.">#</a><a id="Layers1"></a><a id="Layers-in-action"></a>Layers in action.</h2>

<pre><code class="plaintext">             table           perlio          unix
         |           |
         +-----------+    +----------+    +--------+
PerlIO -&gt;|           |---&gt;|  next    |---&gt;|  NULL  |
         +-----------+    +----------+    +--------+
         |           |    |  buffer  |    |   fd   |
         +-----------+    |          |    +--------+
         |           |    +----------+</code></pre>

<p>The above attempts to show how the layer scheme works in a simple case. The application&#39;s <code>PerlIO *</code> points to an entry in the table(s) representing open (allocated) handles. For example the first three slots in the table correspond to <code>stdin</code>,<code>stdout</code> and <code>stderr</code>. The table in turn points to the current &quot;top&quot; layer for the handle - in this case an instance of the generic buffering layer &quot;perlio&quot;. That layer in turn points to the next layer down - in this case the low-level &quot;unix&quot; layer.</p>

<p>The above is roughly equivalent to a &quot;stdio&quot; buffered stream, but with much more flexibility:</p>

<ul>

<li><p>If Unix level <code>read</code>/<code>write</code>/<code>lseek</code> is not appropriate for (say) sockets then the &quot;unix&quot; layer can be replaced (at open time or even dynamically) with a &quot;socket&quot; layer.</p>

</li>
<li><p>Different handles can have different buffering schemes. The &quot;top&quot; layer could be the &quot;mmap&quot; layer if reading disk files was quicker using <code>mmap</code> than <code>read</code>. An &quot;unbuffered&quot; stream can be implemented simply by not having a buffer layer.</p>

</li>
<li><p>Extra layers can be inserted to process the data as it flows through. This was the driving need for including the scheme in perl 5.7.0+ - we needed a mechanism to allow data to be translated between perl&#39;s internal encoding (conceptually at least Unicode as UTF-8), and the &quot;native&quot; format used by the system. This is provided by the &quot;:encoding(xxxx)&quot; layer which typically sits above the buffering layer.</p>

</li>
<li><p>A layer can be added that does &quot;\n&quot; to CRLF translation. This layer can be used on any platform, not just those that normally do such things.</p>

</li>
</ul>

<h2 id="Per-instance-flag-bits"><a class="permalink" href="perliol.html#Per-instance-flag-bits">#</a><a id="Per1"></a>Per-instance flag bits</h2>

<p>The generic flag bits are a hybrid of <code>O_XXXXX</code> style flags deduced from the mode string passed to <code>PerlIO_open()</code>, and state bits for typical buffer layers.</p>

<dl>

<dt id="PERLIO_F_EOF"><a class="permalink" href="perliol.html#PERLIO_F_EOF">#</a>PERLIO_F_EOF</dt>
<dd>

<p>End of file.</p>

</dd>
<dt id="PERLIO_F_CANWRITE"><a class="permalink" href="perliol.html#PERLIO_F_CANWRITE">#</a>PERLIO_F_CANWRITE</dt>
<dd>

<p>Writes are permitted, i.e. opened as &quot;w&quot; or &quot;r+&quot; or &quot;a&quot;, etc.</p>

</dd>
<dt id="PERLIO_F_CANREAD"><a class="permalink" href="perliol.html#PERLIO_F_CANREAD">#</a>PERLIO_F_CANREAD</dt>
<dd>

<p>Reads are permitted i.e. opened &quot;r&quot; or &quot;w+&quot; (or even &quot;a+&quot; - ick).</p>

</dd>
<dt id="PERLIO_F_ERROR"><a class="permalink" href="perliol.html#PERLIO_F_ERROR">#</a>PERLIO_F_ERROR</dt>
<dd>

<p>An error has occurred (for <code>PerlIO_error()</code>).</p>

</dd>
<dt id="PERLIO_F_TRUNCATE"><a class="permalink" href="perliol.html#PERLIO_F_TRUNCATE">#</a>PERLIO_F_TRUNCATE</dt>
<dd>

<p>Truncate file suggested by open mode.</p>

</dd>
<dt id="PERLIO_F_APPEND"><a class="permalink" href="perliol.html#PERLIO_F_APPEND">#</a>PERLIO_F_APPEND</dt>
<dd>

<p>All writes should be appends.</p>

</dd>
<dt id="PERLIO_F_CRLF"><a class="permalink" href="perliol.html#PERLIO_F_CRLF">#</a>PERLIO_F_CRLF</dt>
<dd>

<p>Layer is performing Win32-like &quot;\n&quot; mapped to CR,LF for output and CR,LF mapped to &quot;\n&quot; for input. Normally the provided &quot;crlf&quot; layer is the only layer that need bother about this. <code>PerlIO_binmode()</code> will mess with this flag rather than add/remove layers if the <code>PERLIO_K_CANCRLF</code> bit is set for the layers class.</p>

</dd>
<dt id="PERLIO_F_UTF8"><a class="permalink" href="perliol.html#PERLIO_F_UTF8">#</a>PERLIO_F_UTF8</dt>
<dd>

<p>Data written to this layer should be UTF-8 encoded; data provided by this layer should be considered UTF-8 encoded. Can be set on any layer by &quot;:utf8&quot; dummy layer. Also set on &quot;:encoding&quot; layer.</p>

</dd>
<dt id="PERLIO_F_UNBUF"><a class="permalink" href="perliol.html#PERLIO_F_UNBUF">#</a>PERLIO_F_UNBUF</dt>
<dd>

<p>Layer is unbuffered - i.e. write to next layer down should occur for each write to this layer.</p>

</dd>
<dt id="PERLIO_F_WRBUF"><a class="permalink" href="perliol.html#PERLIO_F_WRBUF">#</a>PERLIO_F_WRBUF</dt>
<dd>

<p>The buffer for this layer currently holds data written to it but not sent to next layer.</p>

</dd>
<dt id="PERLIO_F_RDBUF"><a class="permalink" href="perliol.html#PERLIO_F_RDBUF">#</a>PERLIO_F_RDBUF</dt>
<dd>

<p>The buffer for this layer currently holds unconsumed data read from layer below.</p>

</dd>
<dt id="PERLIO_F_LINEBUF"><a class="permalink" href="perliol.html#PERLIO_F_LINEBUF">#</a>PERLIO_F_LINEBUF</dt>
<dd>

<p>Layer is line buffered. Write data should be passed to next layer down whenever a &quot;\n&quot; is seen. Any data beyond the &quot;\n&quot; should then be processed.</p>

</dd>
<dt id="PERLIO_F_TEMP"><a class="permalink" href="perliol.html#PERLIO_F_TEMP">#</a>PERLIO_F_TEMP</dt>
<dd>

<p>File has been <code>unlink()</code>ed, or should be deleted on <code>close()</code>.</p>

</dd>
<dt id="PERLIO_F_OPEN"><a class="permalink" href="perliol.html#PERLIO_F_OPEN">#</a>PERLIO_F_OPEN</dt>
<dd>

<p>Handle is open.</p>

</dd>
<dt id="PERLIO_F_FASTGETS"><a class="permalink" href="perliol.html#PERLIO_F_FASTGETS">#</a>PERLIO_F_FASTGETS</dt>
<dd>

<p>This instance of this layer supports the &quot;fast <code>gets</code>&quot; interface. Normally set based on <code>PERLIO_K_FASTGETS</code> for the class and by the existence of the function(s) in the table. However a class that normally provides that interface may need to avoid it on a particular instance. The &quot;pending&quot; layer needs to do this when it is pushed above a layer which does not support the interface. (Perl&#39;s <code>sv_gets()</code> does not expect the streams fast <code>gets</code> behaviour to change during one &quot;get&quot;.)</p>

</dd>
</dl>

<h2 id="Methods-in-Detail"><a class="permalink" href="perliol.html#Methods-in-Detail">#</a><a id="Methods"></a>Methods in Detail</h2>

<dl>

<dt id="fsize"><a class="permalink" href="perliol.html#fsize">#</a>fsize</dt>
<dd>

<pre><code>Size_t fsize;</code></pre>

<p>Size of the function table. This is compared against the value PerlIO code &quot;knows&quot; as a compatibility check. Future versions <i>may</i> be able to tolerate layers compiled against an old version of the headers.</p>

</dd>
<dt id="name"><a class="permalink" href="perliol.html#name">#</a>name</dt>
<dd>

<pre><code>char * name;</code></pre>

<p>The name of the layer whose open() method Perl should invoke on open(). For example if the layer is called APR, you will call:</p>

<pre><code>open $fh, &quot;&gt;:APR&quot;, ...</code></pre>

<p>and Perl knows that it has to invoke the PerlIOAPR_open() method implemented by the APR layer.</p>

</dd>
<dt id="size"><a class="permalink" href="perliol.html#size">#</a>size</dt>
<dd>

<pre><code>Size_t size;</code></pre>

<p>The size of the per-instance data structure, e.g.:</p>

<pre><code class="plaintext">sizeof(PerlIOAPR)</code></pre>

<p>If this field is zero then <code>PerlIO_pushed</code> does not malloc anything and assumes layer&#39;s Pushed function will do any required layer stack manipulation - used to avoid malloc/free overhead for dummy layers. If the field is non-zero it must be at least the size of <code>PerlIOl</code>, <code>PerlIO_pushed</code> will allocate memory for the layer&#39;s data structures and link new layer onto the stream&#39;s stack. (If the layer&#39;s Pushed method returns an error indication the layer is popped again.)</p>

</dd>
<dt id="kind"><a class="permalink" href="perliol.html#kind">#</a>kind</dt>
<dd>

<pre><code>IV kind;</code></pre>

<ul>

<li><p>PERLIO_K_BUFFERED</p>

<p>The layer is buffered.</p>

</li>
<li><p>PERLIO_K_RAW</p>

<p>The layer is acceptable to have in a binmode(FH) stack - i.e. it does not (or will configure itself not to) transform bytes passing through it.</p>

</li>
<li><p>PERLIO_K_CANCRLF</p>

<p>Layer can translate between &quot;\n&quot; and CRLF line ends.</p>

</li>
<li><p>PERLIO_K_FASTGETS</p>

<p>Layer allows buffer snooping.</p>

</li>
<li><p>PERLIO_K_MULTIARG</p>

<p>Used when the layer&#39;s open() accepts more arguments than usual. The extra arguments should come not before the <code>MODE</code> argument. When this flag is used it&#39;s up to the layer to validate the args.</p>

</li>
</ul>

</dd>
<dt id="Pushed"><a class="permalink" href="perliol.html#Pushed">#</a>Pushed</dt>
<dd>

<pre><code>IV	(*Pushed)(pTHX_ PerlIO *f,const char *mode, SV *arg);</code></pre>

<p>The only absolutely mandatory method. Called when the layer is pushed onto the stack. The <code>mode</code> argument may be NULL if this occurs post-open. The <code>arg</code> will be non-<code>NULL</code> if an argument string was passed. In most cases this should call <code>PerlIOBase_pushed()</code> to convert <code>mode</code> into the appropriate <code>PERLIO_F_XXXXX</code> flags in addition to any actions the layer itself takes. If a layer is not expecting an argument it need neither save the one passed to it, nor provide <code>Getarg()</code> (it could perhaps <code>Perl_warn</code> that the argument was un-expected).</p>

<p>Returns 0 on success. On failure returns -1 and should set errno.</p>

</dd>
<dt id="Popped"><a class="permalink" href="perliol.html#Popped">#</a>Popped</dt>
<dd>

<pre><code>IV	(*Popped)(pTHX_ PerlIO *f);</code></pre>

<p>Called when the layer is popped from the stack. A layer will normally be popped after <code>Close()</code> is called. But a layer can be popped without being closed if the program is dynamically managing layers on the stream. In such cases <code>Popped()</code> should free any resources (buffers, translation tables, ...) not held directly in the layer&#39;s struct. It should also <code>Unread()</code> any unconsumed data that has been read and buffered from the layer below back to that layer, so that it can be re-provided to what ever is now above.</p>

<p>Returns 0 on success and failure. If <code>Popped()</code> returns <i>true</i> then <i>perlio.c</i> assumes that either the layer has popped itself, or the layer is super special and needs to be retained for other reasons. In most cases it should return <i>false</i>.</p>

</dd>
<dt id="Open"><a class="permalink" href="perliol.html#Open">#</a>Open</dt>
<dd>

<pre><code>PerlIO *	(*Open)(...);</code></pre>

<p>The <code>Open()</code> method has lots of arguments because it combines the functions of perl&#39;s <code>open</code>, <code>PerlIO_open</code>, perl&#39;s <code>sysopen</code>, <code>PerlIO_fdopen</code> and <code>PerlIO_reopen</code>. The full prototype is as follows:</p>

<pre><code> PerlIO *	(*Open)(pTHX_ PerlIO_funcs *tab,
			PerlIO_list_t *layers, IV n,
			const char *mode,
			int fd, int imode, int perm,
			PerlIO *old,
			int narg, SV **args);</code></pre>

<p>Open should (perhaps indirectly) call <code>PerlIO_allocate()</code> to allocate a slot in the table and associate it with the layers information for the opened file, by calling <code>PerlIO_push</code>. The <i>layers</i> is an array of all the layers destined for the <code>PerlIO *</code>, and any arguments passed to them, <i>n</i> is the index into that array of the layer being called. The macro <code>PerlIOArg</code> will return a (possibly <code>NULL</code>) SV * for the argument passed to the layer.</p>

<p>Where a layer opens or takes ownership of a file descriptor, that layer is responsible for getting the file descriptor&#39;s close-on-exec flag into the correct state. The flag should be clear for a file descriptor numbered less than or equal to <code>PL_maxsysfd</code>, and set for any file descriptor numbered higher. For thread safety, when a layer opens a new file descriptor it should if possible open it with the close-on-exec flag initially set.</p>

<p>The <i>mode</i> string is an &quot;<code>fopen()</code>-like&quot; string which would match the regular expression <code>/^[I#]?[rwa]\+?[bt]?$/</code>.</p>

<p>The <code>&#39;I&#39;</code> prefix is used during creation of <code>stdin</code>..<code>stderr</code> via special <code>PerlIO_fdopen</code> calls; the <code>&#39;#&#39;</code> prefix means that this is <code>sysopen</code> and that <i>imode</i> and <i>perm</i> should be passed to <code>PerlLIO_open3</code>; <code>&#39;r&#39;</code> means <b>r</b>ead, <code>&#39;w&#39;</code> means <b>w</b>rite and <code>&#39;a&#39;</code> means <b>a</b>ppend. The <code>&#39;+&#39;</code> suffix means that both reading and writing/appending are permitted. The <code>&#39;b&#39;</code> suffix means file should be binary, and <code>&#39;t&#39;</code> means it is text. (Almost all layers should do the IO in binary mode, and ignore the b/t bits. The <code>:crlf</code> layer should be pushed to handle the distinction.)</p>

<p>If <i>old</i> is not <code>NULL</code> then this is a <code>PerlIO_reopen</code>. Perl itself does not use this (yet?) and semantics are a little vague.</p>

<p>If <i>fd</i> not negative then it is the numeric file descriptor <i>fd</i>, which will be open in a manner compatible with the supplied mode string, the call is thus equivalent to <code>PerlIO_fdopen</code>. In this case <i>nargs</i> will be zero. The file descriptor may have the close-on-exec flag either set or clear; it is the responsibility of the layer that takes ownership of it to get the flag into the correct state.</p>

<p>If <i>nargs</i> is greater than zero then it gives the number of arguments passed to <code>open</code>, otherwise it will be 1 if for example <code>PerlIO_open</code> was called. In simple cases SvPV_nolen(*args) is the pathname to open.</p>

<p>If a layer provides <code>Open()</code> it should normally call the <code>Open()</code> method of next layer down (if any) and then push itself on top if that succeeds. <code>PerlIOBase_open</code> is provided to do exactly that, so in most cases you don&#39;t have to write your own <code>Open()</code> method. If this method is not defined, other layers may have difficulty pushing themselves on top of it during open.</p>

<p>If <code>PerlIO_push</code> was performed and open has failed, it must <code>PerlIO_pop</code> itself, since if it&#39;s not, the layer won&#39;t be removed and may cause bad problems.</p>

<p>Returns <code>NULL</code> on failure.</p>

</dd>
<dt id="Binmode"><a class="permalink" href="perliol.html#Binmode">#</a>Binmode</dt>
<dd>

<pre><code>IV        (*Binmode)(pTHX_ PerlIO *f);</code></pre>

<p>Optional. Used when <code>:raw</code> layer is pushed (explicitly or as a result of binmode(FH)). If not present layer will be popped. If present should configure layer as binary (or pop itself) and return 0. If it returns -1 for error <code>binmode</code> will fail with layer still on the stack.</p>

</dd>
<dt id="Getarg"><a class="permalink" href="perliol.html#Getarg">#</a>Getarg</dt>
<dd>

<pre><code>SV *      (*Getarg)(pTHX_ PerlIO *f,
		    CLONE_PARAMS *param, int flags);</code></pre>

<p>Optional. If present should return an SV * representing the string argument passed to the layer when it was pushed. e.g. &quot;:encoding(ascii)&quot; would return an SvPV with value &quot;ascii&quot;. (<i>param</i> and <i>flags</i> arguments can be ignored in most cases)</p>

<p><code>Dup</code> uses <code>Getarg</code> to retrieve the argument originally passed to <code>Pushed</code>, so you must implement this function if your layer has an extra argument to <code>Pushed</code> and will ever be <code>Dup</code>ed.</p>

</dd>
<dt id="Fileno"><a class="permalink" href="perliol.html#Fileno">#</a>Fileno</dt>
<dd>

<pre><code>IV        (*Fileno)(pTHX_ PerlIO *f);</code></pre>

<p>Returns the Unix/Posix numeric file descriptor for the handle. Normally <code>PerlIOBase_fileno()</code> (which just asks next layer down) will suffice for this.</p>

<p>Returns -1 on error, which is considered to include the case where the layer cannot provide such a file descriptor.</p>

</dd>
<dt id="Dup"><a class="permalink" href="perliol.html#Dup">#</a>Dup</dt>
<dd>

<pre><code>PerlIO * (*Dup)(pTHX_ PerlIO *f, PerlIO *o,
		CLONE_PARAMS *param, int flags);</code></pre>

<p>XXX: Needs more docs.</p>

<p>Used as part of the &quot;clone&quot; process when a thread is spawned (in which case param will be non-NULL) and when a stream is being duplicated via &#39;&amp;&#39; in the <code>open</code>.</p>

<p>Similar to <code>Open</code>, returns PerlIO* on success, <code>NULL</code> on failure.</p>

</dd>
<dt id="Read"><a class="permalink" href="perliol.html#Read">#</a>Read</dt>
<dd>

<pre><code>SSize_t	(*Read)(pTHX_ PerlIO *f, void *vbuf, Size_t count);</code></pre>

<p>Basic read operation.</p>

<p>Typically will call <code>Fill</code> and manipulate pointers (possibly via the API). <code>PerlIOBuf_read()</code> may be suitable for derived classes which provide &quot;fast gets&quot; methods.</p>

<p>Returns actual bytes read, or -1 on an error.</p>

</dd>
<dt id="Unread"><a class="permalink" href="perliol.html#Unread">#</a>Unread</dt>
<dd>

<pre><code>SSize_t	(*Unread)(pTHX_ PerlIO *f,
		  const void *vbuf, Size_t count);</code></pre>

<p>A superset of stdio&#39;s <code>ungetc()</code>. Should arrange for future reads to see the bytes in <code>vbuf</code>. If there is no obviously better implementation then <code>PerlIOBase_unread()</code> provides the function by pushing a &quot;fake&quot; &quot;pending&quot; layer above the calling layer.</p>

<p>Returns the number of unread chars.</p>

</dd>
<dt id="Write"><a class="permalink" href="perliol.html#Write">#</a>Write</dt>
<dd>

<pre><code>SSize_t	(*Write)(PerlIO *f, const void *vbuf, Size_t count);</code></pre>

<p>Basic write operation.</p>

<p>Returns bytes written or -1 on an error.</p>

</dd>
<dt id="Seek"><a class="permalink" href="perliol.html#Seek">#</a>Seek</dt>
<dd>

<pre><code>IV	(*Seek)(pTHX_ PerlIO *f, Off_t offset, int whence);</code></pre>

<p>Position the file pointer. Should normally call its own <code>Flush</code> method and then the <code>Seek</code> method of next layer down.</p>

<p>Returns 0 on success, -1 on failure.</p>

</dd>
<dt id="Tell"><a class="permalink" href="perliol.html#Tell">#</a>Tell</dt>
<dd>

<pre><code>Off_t	(*Tell)(pTHX_ PerlIO *f);</code></pre>

<p>Return the file pointer. May be based on layers cached concept of position to avoid overhead.</p>

<p>Returns -1 on failure to get the file pointer.</p>

</dd>
<dt id="Close"><a class="permalink" href="perliol.html#Close">#</a>Close</dt>
<dd>

<pre><code>IV	(*Close)(pTHX_ PerlIO *f);</code></pre>

<p>Close the stream. Should normally call <code>PerlIOBase_close()</code> to flush itself and close layers below, and then deallocate any data structures (buffers, translation tables, ...) not held directly in the data structure.</p>

<p>Returns 0 on success, -1 on failure.</p>

</dd>
<dt id="Flush"><a class="permalink" href="perliol.html#Flush">#</a>Flush</dt>
<dd>

<pre><code>IV	(*Flush)(pTHX_ PerlIO *f);</code></pre>

<p>Should make stream&#39;s state consistent with layers below. That is, any buffered write data should be written, and file position of lower layers adjusted for data read from below but not actually consumed. (Should perhaps <code>Unread()</code> such data to the lower layer.)</p>

<p>Returns 0 on success, -1 on failure.</p>

</dd>
<dt id="Fill"><a class="permalink" href="perliol.html#Fill">#</a>Fill</dt>
<dd>

<pre><code>IV	(*Fill)(pTHX_ PerlIO *f);</code></pre>

<p>The buffer for this layer should be filled (for read) from layer below. When you &quot;subclass&quot; PerlIOBuf layer, you want to use its <i>_read</i> method and to supply your own fill method, which fills the PerlIOBuf&#39;s buffer.</p>

<p>Returns 0 on success, -1 on failure.</p>

</dd>
<dt id="Eof"><a class="permalink" href="perliol.html#Eof">#</a>Eof</dt>
<dd>

<pre><code>IV	(*Eof)(pTHX_ PerlIO *f);</code></pre>

<p>Return end-of-file indicator. <code>PerlIOBase_eof()</code> is normally sufficient.</p>

<p>Returns 0 on end-of-file, 1 if not end-of-file, -1 on error.</p>

</dd>
<dt id="Error"><a class="permalink" href="perliol.html#Error">#</a>Error</dt>
<dd>

<pre><code>IV	(*Error)(pTHX_ PerlIO *f);</code></pre>

<p>Return error indicator. <code>PerlIOBase_error()</code> is normally sufficient.</p>

<p>Returns 1 if there is an error (usually when <code>PERLIO_F_ERROR</code> is set), 0 otherwise.</p>

</dd>
<dt id="Clearerr"><a class="permalink" href="perliol.html#Clearerr">#</a>Clearerr</dt>
<dd>

<pre><code>void	(*Clearerr)(pTHX_ PerlIO *f);</code></pre>

<p>Clear end-of-file and error indicators. Should call <code>PerlIOBase_clearerr()</code> to set the <code>PERLIO_F_XXXXX</code> flags, which may suffice.</p>

</dd>
<dt id="Setlinebuf"><a class="permalink" href="perliol.html#Setlinebuf">#</a>Setlinebuf</dt>
<dd>

<pre><code>void	(*Setlinebuf)(pTHX_ PerlIO *f);</code></pre>

<p>Mark the stream as line buffered. <code>PerlIOBase_setlinebuf()</code> sets the PERLIO_F_LINEBUF flag and is normally sufficient.</p>

</dd>
<dt id="Get_base"><a class="permalink" href="perliol.html#Get_base">#</a>Get_base</dt>
<dd>

<pre><code>STDCHAR *	(*Get_base)(pTHX_ PerlIO *f);</code></pre>

<p>Allocate (if not already done so) the read buffer for this layer and return pointer to it. Return NULL on failure.</p>

</dd>
<dt id="Get_bufsiz"><a class="permalink" href="perliol.html#Get_bufsiz">#</a>Get_bufsiz</dt>
<dd>

<pre><code>Size_t	(*Get_bufsiz)(pTHX_ PerlIO *f);</code></pre>

<p>Return the number of bytes that last <code>Fill()</code> put in the buffer.</p>

</dd>
<dt id="Get_ptr"><a class="permalink" href="perliol.html#Get_ptr">#</a>Get_ptr</dt>
<dd>

<pre><code>STDCHAR *	(*Get_ptr)(pTHX_ PerlIO *f);</code></pre>

<p>Return the current read pointer relative to this layer&#39;s buffer.</p>

</dd>
<dt id="Get_cnt"><a class="permalink" href="perliol.html#Get_cnt">#</a>Get_cnt</dt>
<dd>

<pre><code>SSize_t	(*Get_cnt)(pTHX_ PerlIO *f);</code></pre>

<p>Return the number of bytes left to be read in the current buffer.</p>

</dd>
<dt id="Set_ptrcnt"><a class="permalink" href="perliol.html#Set_ptrcnt">#</a>Set_ptrcnt</dt>
<dd>

<pre><code>void	(*Set_ptrcnt)(pTHX_ PerlIO *f,
		      STDCHAR *ptr, SSize_t cnt);</code></pre>

<p>Adjust the read pointer and count of bytes to match <code>ptr</code> and/or <code>cnt</code>. The application (or layer above) must ensure they are consistent. (Checking is allowed by the paranoid.)</p>

</dd>
</dl>

<h2 id="Utilities"><a class="permalink" href="perliol.html#Utilities">#</a>Utilities</h2>

<p>To ask for the next layer down use PerlIONext(PerlIO *f).</p>

<p>To check that a PerlIO* is valid use PerlIOValid(PerlIO *f). (All this does is really just to check that the pointer is non-NULL and that the pointer behind that is non-NULL.)</p>

<p>PerlIOBase(PerlIO *f) returns the &quot;Base&quot; pointer, or in other words, the <code>PerlIOl*</code> pointer.</p>

<p>PerlIOSelf(PerlIO* f, type) return the PerlIOBase cast to a type.</p>

<p>Perl_PerlIO_or_Base(PerlIO* f, callback, base, failure, args) either calls the <i>callback</i> from the functions of the layer <i>f</i> (just by the name of the IO function, like &quot;Read&quot;) with the <i>args</i>, or if there is no such callback, calls the <i>base</i> version of the callback with the same args, or if the f is invalid, set errno to EBADF and return <i>failure</i>.</p>

<p>Perl_PerlIO_or_fail(PerlIO* f, callback, failure, args) either calls the <i>callback</i> of the functions of the layer <i>f</i> with the <i>args</i>, or if there is no such callback, set errno to EINVAL. Or if the f is invalid, set errno to EBADF and return <i>failure</i>.</p>

<p>Perl_PerlIO_or_Base_void(PerlIO* f, callback, base, args) either calls the <i>callback</i> of the functions of the layer <i>f</i> with the <i>args</i>, or if there is no such callback, calls the <i>base</i> version of the callback with the same args, or if the f is invalid, set errno to EBADF.</p>

<p>Perl_PerlIO_or_fail_void(PerlIO* f, callback, args) either calls the <i>callback</i> of the functions of the layer <i>f</i> with the <i>args</i>, or if there is no such callback, set errno to EINVAL. Or if the f is invalid, set errno to EBADF.</p>

<h2 id="Implementing-PerlIO-Layers"><a class="permalink" href="perliol.html#Implementing-PerlIO-Layers">#</a><a id="Implementing"></a>Implementing PerlIO Layers</h2>

<p>If you find the implementation document unclear or not sufficient, look at the existing PerlIO layer implementations, which include:</p>

<ul>

<li><p>C implementations</p>

<p>The <i>perlio.c</i> and <i>perliol.h</i> in the Perl core implement the &quot;unix&quot;, &quot;perlio&quot;, &quot;stdio&quot;, &quot;crlf&quot;, &quot;utf8&quot;, &quot;byte&quot;, &quot;raw&quot;, &quot;pending&quot; layers, and also the &quot;mmap&quot; and &quot;win32&quot; layers if applicable. (The &quot;win32&quot; is currently unfinished and unused, to see what is used instead in Win32, see <a href="PerlIO.html#Querying-the-layers-of-filehandles">&quot;Querying the layers of filehandles&quot; in PerlIO</a> .)</p>

<p>PerlIO::encoding, PerlIO::scalar, PerlIO::via in the Perl core.</p>

<p>PerlIO::gzip and APR::PerlIO (mod_perl 2.0) on CPAN.</p>

</li>
<li><p>Perl implementations</p>

<p>PerlIO::via::QuotedPrint in the Perl core and PerlIO::via::* on CPAN.</p>

</li>
</ul>

<p>If you are creating a PerlIO layer, you may want to be lazy, in other words, implement only the methods that interest you. The other methods you can either replace with the &quot;blank&quot; methods</p>

<pre><code class="plaintext">PerlIOBase_noop_ok
PerlIOBase_noop_fail</code></pre>

<p>(which do nothing, and return zero and -1, respectively) or for certain methods you may assume a default behaviour by using a NULL method. The Open method looks for help in the &#39;parent&#39; layer. The following table summarizes the behaviour:</p>

<pre><code>   method      behaviour with NULL

   Clearerr    PerlIOBase_clearerr
   Close       PerlIOBase_close
   Dup         PerlIOBase_dup
   Eof         PerlIOBase_eof
   Error       PerlIOBase_error
   Fileno      PerlIOBase_fileno
   Fill        FAILURE
   Flush       SUCCESS
   Getarg      SUCCESS
   Get_base    FAILURE
   Get_bufsiz  FAILURE
   Get_cnt     FAILURE
   Get_ptr     FAILURE
   Open        INHERITED
   Popped      SUCCESS
   Pushed      SUCCESS
   Read        PerlIOBase_read
   Seek        FAILURE
   Set_cnt     FAILURE
   Set_ptrcnt  FAILURE
   Setlinebuf  PerlIOBase_setlinebuf
   Tell        FAILURE
   Unread      PerlIOBase_unread
   Write       FAILURE

FAILURE        Set errno (to EINVAL in Unixish, to LIB$_INVARG in VMS)
               and return -1 (for numeric return values) or NULL (for
               pointers)
INHERITED      Inherited from the layer below
SUCCESS        Return 0 (for numeric return values) or a pointer </code></pre>

<h2 id="Core-Layers"><a class="permalink" href="perliol.html#Core-Layers">#</a><a id="Core"></a>Core Layers</h2>

<p>The file <code>perlio.c</code> provides the following layers:</p>

<dl>

<dt id="&quot;unix&quot;"><a class="permalink" href="perliol.html#%22unix%22">#</a><a id="unix"></a>&quot;unix&quot;</dt>
<dd>

<p>A basic non-buffered layer which calls Unix/POSIX <code>read()</code>, <code>write()</code>, <code>lseek()</code>, <code>close()</code>. No buffering. Even on platforms that distinguish between O_TEXT and O_BINARY this layer is always O_BINARY.</p>

</dd>
<dt id="&quot;perlio&quot;"><a class="permalink" href="perliol.html#%22perlio%22">#</a><a id="perlio"></a>&quot;perlio&quot;</dt>
<dd>

<p>A very complete generic buffering layer which provides the whole of PerlIO API. It is also intended to be used as a &quot;base class&quot; for other layers. (For example its <code>Read()</code> method is implemented in terms of the <code>Get_cnt()</code>/<code>Get_ptr()</code>/<code>Set_ptrcnt()</code> methods).</p>

<p>&quot;perlio&quot; over &quot;unix&quot; provides a complete replacement for stdio as seen via PerlIO API. This is the default for USE_PERLIO when system&#39;s stdio does not permit perl&#39;s &quot;fast gets&quot; access, and which do not distinguish between <code>O_TEXT</code> and <code>O_BINARY</code>.</p>

</dd>
<dt id="&quot;stdio&quot;"><a class="permalink" href="perliol.html#%22stdio%22">#</a><a id="stdio"></a>&quot;stdio&quot;</dt>
<dd>

<p>A layer which provides the PerlIO API via the layer scheme, but implements it by calling system&#39;s stdio. This is (currently) the default if system&#39;s stdio provides sufficient access to allow perl&#39;s &quot;fast gets&quot; access and which do not distinguish between <code>O_TEXT</code> and <code>O_BINARY</code>.</p>

</dd>
<dt id="&quot;crlf&quot;"><a class="permalink" href="perliol.html#%22crlf%22">#</a><a id="crlf"></a>&quot;crlf&quot;</dt>
<dd>

<p>A layer derived using &quot;perlio&quot; as a base class. It provides Win32-like &quot;\n&quot; to CR,LF translation. Can either be applied above &quot;perlio&quot; or serve as the buffer layer itself. &quot;crlf&quot; over &quot;unix&quot; is the default if system distinguishes between <code>O_TEXT</code> and <code>O_BINARY</code> opens. (At some point &quot;unix&quot; will be replaced by a &quot;native&quot; Win32 IO layer on that platform, as Win32&#39;s read/write layer has various drawbacks.) The &quot;crlf&quot; layer is a reasonable model for a layer which transforms data in some way.</p>

</dd>
<dt id="&quot;mmap&quot;"><a class="permalink" href="perliol.html#%22mmap%22">#</a><a id="mmap"></a>&quot;mmap&quot;</dt>
<dd>

<p>If Configure detects <code>mmap()</code> functions this layer is provided (with &quot;perlio&quot; as a &quot;base&quot;) which does &quot;read&quot; operations by mmap()ing the file. Performance improvement is marginal on modern systems, so it is mainly there as a proof of concept. It is likely to be unbundled from the core at some point. The &quot;mmap&quot; layer is a reasonable model for a minimalist &quot;derived&quot; layer.</p>

</dd>
<dt id="&quot;pending&quot;"><a class="permalink" href="perliol.html#%22pending%22">#</a><a id="pending"></a>&quot;pending&quot;</dt>
<dd>

<p>An &quot;internal&quot; derivative of &quot;perlio&quot; which can be used to provide Unread() function for layers which have no buffer or cannot be bothered. (Basically this layer&#39;s <code>Fill()</code> pops itself off the stack and so resumes reading from layer below.)</p>

</dd>
<dt id="&quot;raw&quot;"><a class="permalink" href="perliol.html#%22raw%22">#</a><a id="raw"></a>&quot;raw&quot;</dt>
<dd>

<p>A dummy layer which never exists on the layer stack. Instead when &quot;pushed&quot; it actually pops the stack removing itself, it then calls Binmode function table entry on all the layers in the stack - normally this (via PerlIOBase_binmode) removes any layers which do not have <code>PERLIO_K_RAW</code> bit set. Layers can modify that behaviour by defining their own Binmode entry.</p>

</dd>
<dt id="&quot;utf8&quot;"><a class="permalink" href="perliol.html#%22utf8%22">#</a><a id="utf8"></a>&quot;utf8&quot;</dt>
<dd>

<p>Another dummy layer. When pushed it pops itself and sets the <code>PERLIO_F_UTF8</code> flag on the layer which was (and now is once more) the top of the stack.</p>

</dd>
</dl>

<p>In addition <i>perlio.c</i> also provides a number of <code>PerlIOBase_xxxx()</code> functions which are intended to be used in the table slots of classes which do not need to do anything special for a particular method.</p>

<h2 id="Extension-Layers"><a class="permalink" href="perliol.html#Extension-Layers">#</a><a id="Extension"></a>Extension Layers</h2>

<p>Layers can be made available by extension modules. When an unknown layer is encountered the PerlIO code will perform the equivalent of :</p>

<pre><code>use PerlIO &#39;layer&#39;;</code></pre>

<p>Where <i>layer</i> is the unknown layer. <i>PerlIO.pm</i> will then attempt to:</p>

<pre><code>require PerlIO::layer;</code></pre>

<p>If after that process the layer is still not defined then the <code>open</code> will fail.</p>

<p>The following extension layers are bundled with perl:</p>

<dl>

<dt id="&quot;:encoding&quot;"><a class="permalink" href="perliol.html#%22:encoding%22">#</a><a id="encoding"></a>&quot;:encoding&quot;</dt>
<dd>

<pre><code>use Encoding;</code></pre>

<p>makes this layer available, although <i>PerlIO.pm</i> &quot;knows&quot; where to find it. It is an example of a layer which takes an argument as it is called thus:</p>

<pre><code>open( $fh, &quot;&lt;:encoding(iso-8859-7)&quot;, $pathname );</code></pre>

</dd>
<dt id="&quot;:scalar&quot;"><a class="permalink" href="perliol.html#%22:scalar%22">#</a><a id="scalar"></a>&quot;:scalar&quot;</dt>
<dd>

<p>Provides support for reading data from and writing data to a scalar.</p>

<pre><code>open( $fh, &quot;+&lt;:scalar&quot;, \$scalar );</code></pre>

<p>When a handle is so opened, then reads get bytes from the string value of <i>$scalar</i>, and writes change the value. In both cases the position in <i>$scalar</i> starts as zero but can be altered via <code>seek</code>, and determined via <code>tell</code>.</p>

<p>Please note that this layer is implied when calling open() thus:</p>

<pre><code>open( $fh, &quot;+&lt;&quot;, \$scalar );</code></pre>

</dd>
<dt id="&quot;:via&quot;"><a class="permalink" href="perliol.html#%22:via%22">#</a><a id="via"></a>&quot;:via&quot;</dt>
<dd>

<p>Provided to allow layers to be implemented as Perl code. For instance:</p>

<pre><code>use PerlIO::via::StripHTML;
open( my $fh, &quot;&lt;:via(StripHTML)&quot;, &quot;index.html&quot; );</code></pre>

<p>See <a href="./PerlIO::via.html">PerlIO::via</a> for details.</p>

</dd>
</dl>

<h1 id="TODO"><a class="permalink" href="perliol.html#TODO">#</a>TODO</h1>

<p>Things that need to be done to improve this document.</p>

<ul>

<li><p>Explain how to make a valid fh without going through open()(i.e. apply a layer). For example if the file is not opened through perl, but we want to get back a fh, like it was opened by Perl.</p>

<p>How PerlIO_apply_layera fits in, where its docs, was it made public?</p>

<p>Currently the example could be something like this:</p>

<pre><code>PerlIO *foo_to_PerlIO(pTHX_ char *mode, ...)
{
    char *mode; /* &quot;w&quot;, &quot;r&quot;, etc */
    const char *layers = &quot;:APR&quot;; /* the layer name */
    PerlIO *f = PerlIO_allocate(aTHX);
    if (!f) {
        return NULL;
    }

    PerlIO_apply_layers(aTHX_ f, mode, layers);

    if (f) {
        PerlIOAPR *st = PerlIOSelf(f, PerlIOAPR);
        /* fill in the st struct, as in _open() */
        st-&gt;file = file;
        PerlIOBase(f)-&gt;flags |= PERLIO_F_OPEN;

        return f;
    }
    return NULL;
}</code></pre>

</li>
<li><p>fix/add the documentation in places marked as XXX.</p>

</li>
<li><p>The handling of errors by the layer is not specified. e.g. when $! should be set explicitly, when the error handling should be just delegated to the top layer.</p>

<p>Probably give some hints on using SETERRNO() or pointers to where they can be found.</p>

</li>
<li><p>I think it would help to give some concrete examples to make it easier to understand the API. Of course I agree that the API has to be concise, but since there is no second document that is more of a guide, I think that it&#39;d make it easier to start with the doc which is an API, but has examples in it in places where things are unclear, to a person who is not a PerlIO guru (yet).</p>

</li>
</ul>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
